<?php
class MsSql_SP_Driver
{
	protected $stmt;
	protected $result;
	
	function prepare($sp_name)
	{
		$this->stmt = mssql_init($sp_name);
		return $this->stmt;
	}
	
	function execute()
	{
		return mssql_execute($this->stmt);
	}
	
	/**
	 * 
	 * @param $para_name
	 * @param $var
	 * @param $type
	 * @param $is_output
	 * @param $is_null
	 * @param $max_len
	 */
	function bind($para_name, $var, $type, $is_output = null, $is_null = null, $max_len = null )
	{
		return mssql_bind($this->stmt, $para_name,$var,$type,$is_output,$is_null, $max_len);
	}
	
	function result($assoc = true)
	{
		$this->result = $this->execute();		
		$rows = array();
	    if($assoc)
	    {
	        $row = array();
	        while($row = mssql_fetch_assoc($this->result))
	        {
	            $rows[] = $row;
	        }
	    }
	    return $rows;
	}
	
	function free()
	{
		if($this->result)
		{
			 mssql_free_result($this->result);
		}
		if($this->stmt)
		{
			mssql_free_statement($this->stmt);
		}
	}
	
	function __destruct()
	{
		$this->free();
	}
}